var e = require("../../../@babel/runtime/helpers/interopRequireDefault"), t = require("../../../@babel/runtime/helpers/defineProperty"), a = e(require("../../../utils/util")), i = getApp();

Page({
    data: {
        checked: !1,
        powerChecked: !1,
        showSearch: !1,
        nickname: "",
        form: {
            cstore_id: null,
            uid: null,
            mobile: "",
            name: "",
            owner_auth: 0,
            status: 0
        }
    },
    onLoad: function(e) {
        var t, a;
        "" !== (null !== (t = e.storeId) && void 0 !== t ? t : "") && (this.setData({
            "form.cstore_id": Number(e.storeId)
        }), console.log(this.data.form.cstore_id)), "" !== (null !== (a = e.itemId) && void 0 !== a ? a : "") && (this.setData({
            "form.id": Number(e.itemId)
        }), this.verifierDetail());
    },
    searchTransfer: function(e) {
        var t = this, i = e.detail.replace(/\D/g, "");
        this.timer && clearTimeout(this.timer), this.timer = setTimeout(function() {
            a.default.debounce(t.dividendSearch(i));
        }, 500);
    },
    dividendSearch: function(e) {
        var t = this, a = "";
        a = i.getNetAddresss("plugin.love.Frontend.Controllers.team-dividend-search.index"), 
        a += "&search=" + e, e && (this.setData({
            nickname: ""
        }), i._getNetWork({
            url: a,
            success: function(e) {
                var a = e.data.data;
                1 === e.data.result ? t.setData({
                    nickname: a[0].nickname,
                    showSearch: !0
                }) : t.setData({
                    nickname: "",
                    showSearch: !0
                });
            },
            fail: function(e) {
                console.log(e);
            }
        }));
    },
    verifierChange: function(e) {
        var t = e.detail;
        this.setData({
            checked: t,
            "form.status": t ? 1 : 0
        });
    },
    powerChange: function(e) {
        var t = e.detail;
        this.setData({
            powerChecked: t,
            "form.owner_auth": t ? 1 : 0
        });
    },
    modelInput: function(e) {
        var a = e.currentTarget.dataset.item, i = e.detail.value;
        this.setData(t({}, a, i));
    },
    verifierDetail: function() {
        var e = this, t = i.getNetAddresss("plugin.coupon-store.frontend.clerk-manage.clerkDetail"), a = {
            cstore_id: this.data.form.cstore_id,
            id: this.data.form.id
        };
        i._postNetWork({
            url: t,
            data: a,
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    var i = e.data.form, n = a.data;
                    i.uid = n.uid, i.mobile = n.mobile, i.name = n.name, i.owner_auth = n.owner_auth, 
                    i.status = n.status, e.setData({
                        form: i,
                        checked: 1 === i.status,
                        powerChecked: 1 === i.owner_auth
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    verifierBtn: function() {
        if (this.data.form.id) {
            if (i._isTextEmpty(this.data.nickname) && this.data.showSearch) return void wx.showToast({
                icon: "none",
                title: "未找到会员",
                duration: 1500
            });
        } else if (i._isTextEmpty(this.data.nickname) && i._isTextEmpty(this.data.form.id)) return void wx.showToast({
            icon: "none",
            title: "未找到会员",
            duration: 1500
        });
        var e = i.getNetAddresss("plugin.coupon-store.frontend.clerk-manage.changeClerk");
        i._postNetWork({
            url: e,
            data: this.data.form,
            success: function(e) {
                var t = e.data;
                1 == t.result ? (wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                }), setTimeout(function() {
                    wx.navigateBack({
                        dalta: 2
                    });
                }, 500)) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});